package com.zb.system.controller;


import com.zb.entity.AccounLoginInfo;
import com.zb.entity.SelectVo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjSmsReceiveRoleService;
import com.zb.service.ZjSmsTemplateService;
import com.zb.utils.TokenUtil;
import com.zb.vo.SmsReceiveRoleVo;
import com.zb.vo.SmsTemplateListSearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 商家短信模板表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-03-21
 */
@Api(tags = "系统短信模板类接口")
@RestController
@RequestMapping("/system/sms/template")
public class ZjSmsTemplateController {
    @Resource
    private ZjSmsTemplateService smsTemplateService;
    @Resource
    private ZjSmsReceiveRoleService smsReceiveRoleService;

    @ApiOperation("同步短信模板")
    @GetMapping("/syncSmsTemplate")
    public Result syncSmsTemplate(HttpServletRequest request) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        smsTemplateService.syncSmsTemplate(loginInfo);
        return Result.success("短信模板同步成功");
    }

    @ApiOperation("获取短信模板列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody @ApiParam(value = "搜索关键词：模板名称/模板内容") SmsTemplateListSearchVo search) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取短信模板列表成功").data(smsTemplateService.getList(custAccId, search));
    }

    @ApiOperation("获取短信模板详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "短信模板ID") Long id) {
        return Result.success("获取短信模板详情成功").data(PageUtil.row(smsTemplateService.getDetail(id)));
    }

    @ApiOperation("启用或禁用短信模板")
    @PostMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "短信模板状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "短信模板ID", required = true) List<Long> ids) {
        smsTemplateService.updateDisableBatchById(ids, status);
        return Result.success(status? "禁用短信模板成功" : "启用短信模板成功");
    }

    @ApiOperation("根据短信模板ID获取短信接收角色类型")
    @GetMapping("/getRoleType/{id}")
    public Result getRoleType(@PathVariable @ApiParam(value = "短信模板ID") Long id) {
        return Result.success("获取短信接收角色类型成功").data(PageUtil.rows(smsReceiveRoleService.getRoleTypeBySmsTemplateId(id)));
    }

    @ApiOperation("保存短信接收者类型")
    @PostMapping("/saveRoleType/{id}")
    public Result saveRoleType(HttpServletRequest request, @PathVariable @ApiParam(value = "短信模板ID", required = true) Long id,
                               @RequestBody @ApiParam(value = "短信接收者角色类型ID") SmsReceiveRoleVo receiveRoleVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        smsReceiveRoleService.save(custAccId, id, receiveRoleVo);
        return Result.success("保存短信接收者类型成功");
    }




}
